{template "header.html"}

<p>
    {if $run_time}
    <font color="green">{dr_lang('最近自动执行时间为：%s', $run_time)}</font>
    {else}
    <font color="red">{dr_lang('当前服务器没有设置自动任务脚本')}</font>
    {/if}
</p>

<form action="" class="form-horizontal" method="post" name="myform" id="myform">
    {$form}
    <div class="myfbody">
    <div class="portlet bordered light ">
        <div class="portlet-title tabbable-line">
            <ul class="nav nav-tabs" style="float:left;">
                <li class="{if $page==0}active{/if}">
                    <a href="#tab_0" data-toggle="tab" onclick="$('#dr_page').val('0')"> <i class="fa fa-cog"></i> {dr_lang('缓存设置')} </a>
                </li>
            </ul>
        </div>
        <div class="portlet-body">
            <div class="tab-content">

                <div class="tab-pane {if $page==0}active{/if}" id="tab_0">
                    <div class="form-body">

                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('缓存开关')}</label>
                            <div class="col-md-9">
                                <div class="mt-radio-inline">
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[SYS_CACHE]" value="1" {if $data['SYS_CACHE']}checked{/if} /> {dr_lang('开启')} <span></span></label>
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[SYS_CACHE]" value="0" {if empty($data['SYS_CACHE'])}checked{/if} /> {dr_lang('关闭')} <span></span></label>
                                </div>
                                <span class="help-block">{dr_lang('推荐开启缓存功能，可以大大提高系统运行效率')}</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('清理方式')}</label>
                            <div class="col-md-9">
                                <div class="mt-radio-inline">
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[SYS_CACHE_CLEAR]" value="0" {if empty($data['SYS_CACHE_CLEAR'])}checked{/if} /> {dr_lang('自动')} <span></span></label>
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[SYS_CACHE_CLEAR]" value="1" {if $data['SYS_CACHE_CLEAR']}checked{/if} /> {dr_lang('手动')} <span></span></label>
                                </div>
                                <span class="help-block">{dr_lang('自动表示后台操作时会自动清理缓存数据')}</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('缓存方式')}</label>
                            <div class="col-md-9">
                                <div class="mt-radio-inline">
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[SYS_CACHE_TYPE]" value="0" {if empty($data['SYS_CACHE_TYPE'])}checked{/if} /> {dr_lang('文件')} <span></span></label>
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[SYS_CACHE_TYPE]" value="1" {if $data['SYS_CACHE_TYPE'] == 1}checked{/if} /> Memcached <span></span></label>
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[SYS_CACHE_TYPE]" value="2" {if $data['SYS_CACHE_TYPE'] == 2}checked{/if} /> Redis <span></span></label>
                                </div>
                            </div>
                        </div>


                        <input type="hidden" name="data[SYS_CACHE_SMS]" value="{intval($data['SYS_CACHE_SMS'])}">

                        {loop $cache_var $value $name}
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang($name)}</label>
                            <div class="col-md-9">
                                <div class="input-inline input-medium">
                                    <div class="input-group">
                                        <input type="text" name="data[SYS_CACHE_{$value}]" value="{floatval($data['SYS_CACHE_'.$value])}" class="form-control">
                                        <span class="input-group-addon">
                                            {dr_lang('小时')}
                                        </span>
                                    </div>
                                </div>
                                <span class="help-inline"> {dr_lang('0表示不缓存')} </span>
                            </div>
                        </div>
                        {/loop}

                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('任务自动清理')}</label>
                            <div class="col-md-9">
                                <div class="input-inline input-medium">
                                    <div class="input-group">
                                        <input type="text" name="data[SYS_CACHE_CRON]" value="{intval($data['SYS_CACHE_CRON'])}" class="form-control">
                                        <span class="input-group-addon">
                                            {dr_lang('天')}
                                        </span>
                                    </div>
                                </div>
                                <span class="help-inline"> {dr_lang('缓存最大储存的时间，过期后将被任务队列清理缓存')} </span>
                            </div>
                        </div>


                    </div>
                </div>



            </div>
        </div>
    </div>
    </div>
    <div class="portlet-body form myfooter">
        <div class="form-actions text-center">
            <label><button type="button" onclick="dr_ajax_submit('{dr_now_url()}&page='+$('#dr_page').val(), 'myform', '2000')" class="btn blue"> <i class="fa fa-save"></i> {dr_lang('保存')}</button></label>
            <label><button type="button" onclick="dr_test_cache()" class="btn red"> <i class="fa fa-cloud"></i> {dr_lang('测试')}</button></label>
        </div>
    </div>
</form>

<script type="text/javascript">
    function dr_test_cache() {
        var loading = layer.load(2, {
            shade: [0.3,'#fff'], //0.1透明度的白色背景
            time: 10000
        });
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "{dr_url('api/test_cache')}",
			data: $('#myform').serialize(),
            success: function(json) {
                layer.close(loading);
                dr_tips(json.code, json.msg);
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, this, thrownError);
            }
        });
    }
</script>
{template "footer.html"}